package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.EventType;
import com.ruoyi.house_sale.service.IEventTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件类型Controller
 * 
 * @author ruoyi
 * @date 2022-03-28
 */
@RestController
@RequestMapping("/house_sale/EventType")
public class EventTypeController extends BaseController
{
    @Autowired
    private IEventTypeService eventTypeService;

    /**
     * 查询事件类型列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:EventType:list')")
    @GetMapping("/list")
    public TableDataInfo list(EventType eventType)
    {
        startPage();
        List<EventType> list = eventTypeService.selectEventTypeList(eventType);
        return getDataTable(list);
    }

    /**
     * 导出事件类型列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:EventType:export')")
    @Log(title = "事件类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EventType eventType)
    {
        List<EventType> list = eventTypeService.selectEventTypeList(eventType);
        ExcelUtil<EventType> util = new ExcelUtil<EventType>(EventType.class);
        util.exportExcel(response, list, "事件类型数据");
    }

    /**
     * 获取事件类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:EventType:query')")
    @GetMapping(value = "/{eventtypeid}")
    public AjaxResult getInfo(@PathVariable("eventtypeid") Long eventtypeid)
    {
        return AjaxResult.success(eventTypeService.selectEventTypeByEventtypeid(eventtypeid));
    }

    /**
     * 新增事件类型
     */
    @PreAuthorize("@ss.hasPermi('house_sale:EventType:add')")
    @Log(title = "事件类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EventType eventType)
    {
        return toAjax(eventTypeService.insertEventType(eventType));
    }

    /**
     * 修改事件类型
     */
    @PreAuthorize("@ss.hasPermi('house_sale:EventType:edit')")
    @Log(title = "事件类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EventType eventType)
    {
        return toAjax(eventTypeService.updateEventType(eventType));
    }

    /**
     * 删除事件类型
     */
    @PreAuthorize("@ss.hasPermi('house_sale:EventType:remove')")
    @Log(title = "事件类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eventtypeids}")
    public AjaxResult remove(@PathVariable Long[] eventtypeids)
    {
        return toAjax(eventTypeService.deleteEventTypeByEventtypeids(eventtypeids));
    }

}
